function save_workspace_functions(elements){
    $(elements).dialog({autoOpen: false, 
                    modal: true,
                    width: 400,
                    dialogClass: 'brochure_dialogButtons',
                    buttons: {                            
                        "Save": function() {
                        },
                        Cancel: function() {
                            $( this ).dialog( "close" );
                        }
    }});
    $(elements).dialog('open');
    $("div.brochure_dialogButtons div button:nth-child(1)").addClass("sBrochureDB");
}

/*  ================================================
    ========= Setting page for brochure   ==========
    @self = Onclick of the creating number of pages
    @page_type = type of page if(Create / Update)
    @page_num = number of pages
    ================================================ */
function set_page_brochure(self,page_type,page_num) {
    self.html('<img src="/images/loaders/3d_2.gif" style="width: 18px;height: 18px;">');
    $(".brochure_none").show();
    $(".brochure_workspace").hide();
    $(".brochure_builder").hide();
    
    setTimeout(function(){
        if (page_type == "create_page") {
            if (page_num == ""){ 
                alert("Null")
            }else{
                $(".brochure_none").hide();
                $(".brochure_workspace").show();
                $(".brochure_builder").show();
                
                // Create workspace depends on the number of page
                create_workspace(page_num,"1");
                
                // Create pagination
                create_pagination("1",page_num,'#brochure_pagination')
                
                $(".create_pages").text("Go");
                
                // Resizable Brochure Workspace
                    $(".brochure_builder").resizable({
                        maxWidth: 991,
                        minWidth: 991,
                        minHeight: 501
                    });
            }
        }else{
            var cur_page = $(".page_update_val").val();
            create_pagination(cur_page,page_num,'#brochure_pagination')
            
            $(".create_pages").text("Go");
            
            // Resizable Brochure Workspace
                $(".brochure_builder").resizable({
                    maxWidth: 991,
                    minWidth: 991,
                    minHeight: 501    
                });
        }
        
        
    },1000);
}

/*  ================================================
    =====  Functions on Creating 
                    Workspace on the brochure ======
    @cur_page = Current page
    @page_num = number of pages
    ================================================ */
function create_workspace(page_num,cur_page){
    var ret = "";
    for(var i = 1; i <= page_num; i++){
        var add_id = 'brochure_builder_' + i;
        if (i == cur_page) {
            ret += '<div id="' + add_id + '" class="brochure appendControl"></div>';
        }else{
            ret += '<div id="' + add_id + '" class="brochure hide"></div>';
        }
    }
    $(".brochure_builder").html(ret);
}

/*  ================================================
    =====  Functions on Creating pagination
    where user set number of pages on the brochure======
    @cur_page = Current page
    @page_num = number of pages
    @elements = location where you want to show the pagination
    ================================================ */
function create_pagination(cur_page,page_num,elements){
    var options = {
        currentPage: cur_page,
        totalPages: page_num,
        alignment:'center',
        itemTexts: function (type, page, current) {
                switch (type) {
                case "first":
                    return "First";
                case "prev":
                    return "Previous";
                case "next":
                    return "Next";
                case "last":
                    return "Last";
                case "page":
                    return page;
                }
        },
        shouldShowPage:function(type, page, current){
            switch(type)
            {
                case "first":
                default:
                    return true;
            }
        },
        onPageChanged: function(e,oldPage,newPage){
            $("#brochure_builder_" + oldPage).addClass('hide').removeClass('appendControl');
            $("#brochure_builder_" + newPage).removeClass('hide').addClass('appendControl');
        }
    }

    $(elements).bootstrapPaginator(options);
    
}